import axios from 'axios'
import router from "../router"

//request
axios.interceptors.request.use(function (config) {
    // 在发送请求之前做些什么
    // console.log(config)
    return config;
  }, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
  });
// response
axios.interceptors.response.use((response) => {
    // response.config.headers['Content-Type']='application/json; charset=UTF-8';
    // config.Headers['Content-Type'] = 'application/json;charset=UTF-8';
    if(response.data.code === '403' ){
        // router.replace({
        //     path: '/login',
        // });
        return response;
    } else {
        return response;
    }
}, (error) => {
    if (error.response) {
        router.replace({
            path: '/user/login',
        });
    }
    return Promise.reject(error);
})
axios.defaults.withCredentials = true//允许前端传cookie值给后端
// console.log(axios.defaults.headers)
